package com.itheima.exception;

import com.itheima.domain.Student;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Test04 {

    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        Student student = new Student();

        System.out.println("请输入姓名");
        String name = sc.nextLine();
        student.setName(name);
        while (true) {
            try {
                System.out.println("请输入年龄");
                String age = sc.nextLine();
                student.setAge( Integer.valueOf(age));
                break;
            } catch (NumberFormatException e) {
                System.out.println("你倒是输入数字啊");
                continue;
            }catch (AgeOutOfBoundsException e){
                System.out.println(e.toString());
                System.out.println("我只要18-25的");
                continue;
            }

        }

        System.out.println(student);
    }
}
